package com.example.simple.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.simple.annotation.Log;
import lombok.Data;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName SimpleController
 * @Description
 * @Author liukun
 * @Date 2022/6/9 09:02
 */
@RestController
@Slf4j
public class SimpleController {

    /**
     * 主要就是在这里使用，@Log注解，加了这个注解的，才会被LogAspect切到
     * @param pathVariable
     * @param reqDto
     * @return
     */
    @RequestMapping("/test/aop/{pathVariable}")
    @Log(module = "LOGIN_MODULE")
    public ReturnDto aopTestController(
            @PathVariable("pathVariable") String pathVariable,
            @RequestBody ReqDto reqDto) {

        log.info("SimpleController输出pathVariable={}", pathVariable);
        log.info("SimpleController输出reqDto={}", JSONObject.toJSONString(reqDto));
        return new ReturnDto().setName("Kelvin").setAge(18);

    }

}

@Data
class ReqDto {
    String password;
}

@Data
@Accessors(chain = true)
class ReturnDto {
    String name;
    int age;
}
